//
//  MNHomeViewController.swift
//  aj
//
//  Created by leeqb on 11/18/15.
//  Copyright © 2015 powerlee. All rights reserved.
//

import UIKit

var g_mainController: MNHomeViewController!

class MNHomeViewController: AJBaseViewController {
    var familyList: [[NSObject : AnyObject]]!
    var centerFragment1: MNCenterTreeFragment!
    var centerFragment2: MNCenterTreeFragment!
    var centerFragment3: MNCenterTreeFragment!
    var centerFragment4: MNCenterTreeFragment!
    
    @IBOutlet weak var view35: UIView!
    @IBOutlet weak var view4: UIView!
    @IBOutlet weak var view47: UIView!
    @IBOutlet weak var view55: UIView!

    /*
    3.5寸，320.0,480.0
    4寸，320.0,568.0
    4.7寸，375.0,667.0
    414.0,736.0
    */
    override func viewDidLoad() {
        super.viewDidLoad()
        
        g_mainController = self
        AJBaseController.addWhiteStatusBar(self)
        //print("\(screenWidth),\(screenHeight)")
        //print(DataManager.userInfo())
        
        view35.hidden = true
        view4.hidden = true
        view47.hidden = true
        view55.hidden = true
        
        if SCREEN_HEIGHT == 480 {
            view35.hidden = false
        } else if SCREEN_HEIGHT == 568 {
            view4.hidden = false
        } else if SCREEN_HEIGHT == 667 {
            view47.hidden = false
        } else if SCREEN_HEIGHT == 736 {
            view55.hidden = false
        }
        
        centerFragment1 = self.childViewControllers[0] as! MNCenterTreeFragment
        centerFragment2 = self.childViewControllers[1] as! MNCenterTreeFragment
        centerFragment3 = self.childViewControllers[2] as! MNCenterTreeFragment
        centerFragment4 = self.childViewControllers[3] as! MNCenterTreeFragment
    }
    
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        self.requestData()
    }
    
    private func requestData() {
        // 刷新用户信息
        DataManager.refreshUserInfo(userId, success: { () -> Void in
            }, failed: { () -> Void in
        })
        
        // 获取用户列表
        let params = ["userId": userId]
        AJNetworkHelper.instance.post("aj_my_family_list", parameters: params, success: { (operation: AFHTTPRequestOperation!, responseObject: AnyObject!) -> Void in
            let result = responseObject["result"] as! [NSObject : AnyObject]
            self.familyList = result["familyList"] as! [[NSObject : AnyObject]]
            self.centerFragment1.familyList = self.familyList
            //self.centerFragment2.familyList = self.familyList
            //self.centerFragment3.familyList = self.familyList
            //self.centerFragment4.familyList = self.familyList
            }, failed: { (operation: AFHTTPRequestOperation!, error: NSError!) -> Void in
            }) { () -> Void in
        }
    }
    
    @IBAction func moreMemberClick(sender: UIButton) {
        print("moreMemberClick")
        let vc = LB("More", vcName: "MoreFamilyMember") as! UIViewController
        self.navigationController?.pushViewController(vc, animated: true)
    }
}
